package com.whyx.project.openapi.handle;

import com.whyx.project.openapi.config.JT808ServerConfig;
import exsun.jt808.data.util.FtpUtils;
import exsun.jt808.data.util.executorsThread.FixedThreadHandleRunnable;
import org.springframework.web.multipart.MultipartFile;

import java.text.SimpleDateFormat;
import java.util.Date;


public class FileUploadHandle {
    /*
    存储文件数据至ftp服务器
     */
    public static boolean saveToFTP(JT808ServerConfig jt808ServerConfig, String fileName, String filePath, byte[] data)throws Exception{
        boolean result = FixedThreadHandleRunnable.ftpSave(jt808ServerConfig.getJt808FtpServer(),
                jt808ServerConfig.getJt808FtpPort(), jt808ServerConfig.getJt808FtpUserName(),
                jt808ServerConfig.getJt808FtpPassword(), jt808ServerConfig.getJt808FtpBasePath(),
                filePath,fileName,data,jt808ServerConfig.getJt808FtpTimeOut());
        return result;
    }

    public static String getFilePath(String phoneNum){
        return "/SaveFile/"+new SimpleDateFormat("yyyy-MM-dd").format(new Date())
                + "/" + phoneNum;
    }

    public static String getFileName(){
        return new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
    }

}
